package health.lm.com.shop;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.shop.fragment.PeopleChainFragment;

public class MainActivity extends XActivity {
    private Fragment mCurrentFragment;

    /**
     * 显示fragment
     *
     * @param frameLayoutId frameLayoutId
     * @param fragment      fragment
     */
    private void addFragment(int frameLayoutId, Fragment fragment) {
        if (fragment != null) {
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            if (fragment.isAdded()) {
                if (mCurrentFragment != null) {
                    transaction.hide(mCurrentFragment).show(fragment);
                } else {
                    transaction.show(fragment);
                }
            } else {
                if (mCurrentFragment != null) {
                    transaction.hide(mCurrentFragment).add(frameLayoutId, fragment);
                } else {
                    transaction.add(frameLayoutId, fragment);
                }
            }
            mCurrentFragment = fragment;
            transaction.commit();
        }
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        addFragment(R.id.container, new PeopleChainFragment());
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_classroom;
    }

    @Override
    public Object newP() {
        return null;
    }
}
